home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / apl / pedp.lzh / ped.c < prev    next >
C/C++ Source or Header  |  1996-01-13  |  6KB  |  226 lines

  1. #include <stdio.h>
  2.  
  3. #include "wlib.h"
  4. #include "parts.h"
  5. #include "winop.h"
  6.  
  7. int        WindowHeapSize = 4 * 1024 ;
  8.  
  9. /*
  10.     proto get.c > temp
  11. */
  12. int        RequestExec( WindowID, EventInfo* );
  13.  
  14. extern    PatternOpen( WindowID, char*, int, int, int, Sheet* );
  15.  
  16. static    int        inputflag, typeflag = 1 ;
  17. static    DrawBuf        drawbuf[15] ;
  18. static    char    FileName[98], Xchar[10], Ychar[10] ;
  19.  
  20. void    WindowMain( argc, argv )
  21. int        argc ;
  22. char    *argv[] ;
  23. {
  24.     int        x = 150, y = 120, dmy ;
  25.  
  26.     argc = AnalizeArgs( argc, argv, &x, &y, &dmy, &dmy );
  27.     if( argc >= 2 )
  28.         strcpy( FileName, *++argv );
  29.     WindowTitleOpen( x, y, 200, 120, NULL, "Pattern Editor +", Close|Push, RequestExec );
  30. }
  31.  
  32.  
  33. SrcSelect( wp, n )
  34. WindowID    wp;
  35. {
  36.     if ( n == 1 || n == 2 ){
  37.         typeflag = n ;
  38.         n = AttrReverse * ( n == 2 ) + 1 ;
  39.         DrawSetSymbol( drawbuf+9, 60, 90+4, "Source", n, 16 );
  40.         DrawSetSymbol( drawbuf+10, 120, 90+4, "Include", n ^ AttrReverse, 16 );
  41.         WindowDraw( wp, drawbuf+9, 2 );
  42.     }
  43. }
  44.  
  45. int        RequestExec( wp, info )
  46. WindowID    wp ;
  47. EventInfo    *info ;
  48. {
  49.     int        n, i, x, y ;
  50.     DrawBuf    buf[10], *bufp ;
  51.     char    **p ;
  52.     Sheet    *sp ;
  53.  
  54.     static    InputClass    input[3] ;
  55.  
  56.     switch( info->option )
  57.     {
  58.         case EventOpen :
  59.             InputSet( input, 100, 36, FileName, 88, AttrDefault, 12 );
  60.             InputSetCursorVisible( NULL, input, FALSE );
  61.             InputSet( input+1, 100, 54, Xchar, 5, AttrDefault, 16 );
  62.             InputSetCursorVisible( NULL, input+1, FALSE );
  63.             InputSet( input+2, 100, 74, Ychar, 5, AttrDefault, 16 );
  64.             InputSetCursorVisible( NULL, input+2, FALSE );
  65. /*            strcpy( FileName, "" );*/
  66.             strcpy( Xchar, "16" );
  67.             strcpy( Ychar, "16" );
  68.  
  69.             DrawSetClear( drawbuf, 1 );
  70.             x = ( 200 - sizeof( "Edit Pattern Data" )*8 ) / 2 ;
  71.             DrawSetSymbol( drawbuf+1, x,  5+4, "Edit Pattern Data",
  72.                             AttrDefault+AttrHighLight, 16 );
  73.             DrawSetSymbol( drawbuf+2, 8, 30+4, "File Name", AttrDefault, 16 );
  74.             DrawSetSymbol( drawbuf+3, 8, 50+4, "X size", AttrDefault, 16 );
  75.             DrawSetSymbol( drawbuf+4, 8, 70+4, "Y size", AttrDefault, 16 );
  76.             DrawSetLine( drawbuf+5, 100, 34+17, 180, 34+17, 0, OptionLine );
  77.             DrawSetLine( drawbuf+6, 100, 54+17, 140, 54+17, 0, OptionLine );
  78.             DrawSetLine( drawbuf+7, 100, 74+17, 140, 74+17, 0, OptionLine );
  79.  
  80.             DrawSetSymbol( drawbuf+8, 8, 90+4, "Type", AttrDefault, 16 );
  81.             DrawSetSymbol( drawbuf+9, 60, 90+4, "Source", 1, 16 );
  82.             DrawSetSymbol( drawbuf+10, 120, 90+4, "Include", AttrDefault, 16 );
  83.  
  84.             WindowRedraw( wp );
  85.             WindowSetEventAttr( wp, EventAttrDefault|EventMouseMoveON|EventUserON );
  86.             break ;
  87.         case EventRedraw :
  88.             WindowDraw( wp, drawbuf, 11 );
  89.             for( i = 0 ; i < 3 ; ++i )
  90.             {
  91.                 n = InputSetDraw( buf, input+i );
  92.                 WindowDraw( wp, buf, n );
  93.             }
  94.             break ;
  95.         case EventClose :
  96.             WindowClose( wp );
  97.             WindowConnectionClose();
  98.             return( TRUE );
  99.         case EventMouseEnter :
  100.             n = InputSetCursorVisible( buf, input+inputflag, TRUE );
  101.             WindowDraw( wp, buf, n );
  102.             break ;
  103.         case EventMouseOut :
  104.             n = InputSetCursorVisible( buf, input+inputflag, FALSE );
  105.             WindowDraw( wp, buf, n );
  106.             break ;
  107.         case EventMouseMove :
  108.         case EventMouseSwitch :
  109.             if ( info->LeftON )
  110.             {
  111.                 if ( 94 <= info->y && info->y < 110 )
  112.                 {
  113.                     n = info->x / 60 ;
  114.                     SrcSelect( wp, n );
  115.                 }
  116.                 for( i = 0 ; i < 3 ; ++i )
  117.                 {
  118.                     if ( i != inputflag &&
  119.                          ClipInner( (ClipClass*)(input+i), info->x, info->y ) )
  120.                     {
  121.                         bufp = buf ;
  122.                         bufp += InputSetCursorVisible( bufp, input+inputflag, FALSE );
  123.                         inputflag = i ;
  124.                         bufp += InputSetCursorVisible( bufp, input+inputflag, TRUE );
  125.                         WindowDraw( wp, buf, bufp - buf );
  126.                     }
  127.                 }
  128.                 if( ClipInner( (ClipClass*)(input),
  129.                             info->x, info->y ) ){
  130.                     UserSendOperation( wp, info,
  131.                         UserString, FileName );
  132.                     return    TRUE;
  133.                 }
  134.             }
  135.             return( DefaultMouseOperation( wp, info ) );
  136.             break ;
  137.         case EventKey :
  138.             bufp = buf ;
  139.             switch( info->KeyCode )
  140.             {
  141.                 case FuncKeyF(1):
  142.                     SrcSelect( wp, 1 );
  143.                     return    TRUE;
  144.                 case FuncKeyF(2):
  145.                     SrcSelect( wp, 2 );
  146.                     return    TRUE;
  147.                 case FuncKeyUp :
  148.                 case 0x10: /* CTRL-P */
  149.                 case 5 : /* CTRL-E */
  150.                     if ( inputflag > 0 )
  151.                     {
  152.                         bufp += InputSetCursorVisible( bufp, input+inputflag, FALSE );
  153.                         inputflag -- ;
  154.                         bufp += InputSetCursorVisible( bufp, input+inputflag, TRUE );
  155.                     }
  156.                     break ;
  157.                 case FuncKeyDown :
  158.                 case 0xe: /* CTRL-N */
  159.                 case 0x18 : /* CTRL-X */
  160.                     if ( inputflag < 2 )
  161.                     {
  162.                         bufp += InputSetCursorVisible( bufp, input+inputflag, FALSE );
  163.                         inputflag ++ ;
  164.                         bufp += InputSetCursorVisible( bufp, input+inputflag, TRUE );
  165.                     }
  166.                     break ;
  167.                 case 13 : /* ENTER */
  168.                     x = atoi( Xchar );
  169.                     y = atoi( Ychar );
  170.                     if ( x > 0 && y > 0 && strlen( FileName ) > 0 )
  171.                     {
  172.                         if ( PatternOpen( wp, FileName, x, y, typeflag, NULL ) )
  173.                         {
  174.                             WindowSetAttr( wp, WindowAttrInvisible );
  175.                         }
  176.                         else
  177.                         {
  178.                             WindowClose( wp );
  179.                             WindowConnectionClose();
  180.                             return( TRUE );
  181.                         }
  182.                     }
  183.                     break ;
  184.                 default :
  185.                     bufp += InputKey( bufp, input+inputflag, info->KeyCode, info->ShiftStat );
  186.             }
  187.             if ( bufp > buf )
  188.                 WindowDraw( wp, buf, bufp - buf );
  189.             break ;
  190.         case EventUser :
  191.             sp = NULL ;
  192.             switch( info->ComData )
  193.             {
  194.                 case UserPaste :
  195.                 case UserString :
  196.                     strcpy( FileName, info->ComBuffer );
  197.                     break ;
  198.                 case UserStrings :
  199.                     p = info->ComBuffer ;
  200.                     if ( p[0] == NULL )
  201.                         return( TRUE );
  202.                     strcpy( FileName, p[0] );
  203.                     break ;
  204.                 case UserSheet :
  205.                     if ( strlen( FileName ) == 0 )
  206.                         strcpy( FileName, "untitled" );
  207.                     sp = info->ComBuffer ;
  208.                     break ;
  209.                 default :
  210.                     return( FALSE );
  211.             }
  212.             if ( PatternOpen( wp, FileName, 0, 0, typeflag, sp ) )
  213.             {
  214.                 WindowSetAttr( wp, WindowAttrInvisible );
  215.             }
  216.             else
  217.             {
  218.                 WindowClose( wp );
  219.                 WindowConnectionClose();
  220.                 return( TRUE );
  221.             }
  222.             break ;
  223.     }
  224.     return( TRUE );
  225. }
  226.